package com.wangmengtao.upms.controller;

import com.wangmengtao.upms.dto.ServerResponse;
import com.wangmengtao.upms.model.UpmsUser;
import com.wangmengtao.upms.service.UpmsDeptUserService;
import com.wangmengtao.upms.service.UpmsUserService;
import com.wangmengtao.upms.util.ServerResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: UpmsUserController
 * @Description: TODO
 * @Author: WangMengtao
 * @Data: 2019/6/5 17:15
 * @Version: 1.0.0
 */
@RestController
public class UpmsUserController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UpmsUserService upmsUserService;
    @Autowired
    private UpmsDeptUserService upmsDeptUserService;
    @PostMapping(value = "/users")
    public Object create(UpmsUser upmsUser) {
        return upmsUserService.insert(upmsUser);
    }

    @DeleteMapping(value = "/users/{id}")
    public Object deleteById(@PathVariable("id") Long id) {
        logger.info("删除ID=" + id);
        return upmsUserService.deleteById(id);
    }

    @PutMapping(value = "/users")
    public Object update(UpmsUser upmsUser) {
        return upmsUserService.update(upmsUser);
    }

    @GetMapping(value = "/users/{id}")
    public ServerResponse<UpmsUser> getByid(@PathVariable("id") Long id) {
        logger.info("查询ID ="  + id + "用户信息");
        return ServerResponseUtil.success(upmsUserService.getById(id));
    }

    @GetMapping(value = "/users")
    public ServerResponse<UpmsUser> list() {
        return ServerResponseUtil.success(upmsUserService.list());
    }

    @GetMapping(value = "/depts/{id}/user")
    public Object ListByDeptId(@PathVariable("id") Long id) throws Exception{
        return upmsDeptUserService.listByDeptId(id);
    }

}
